
#ifndef XSAN_TYPES_H
#define XSAN_TYPES_H

#include <stdint.h>
#include <stdbool.h>
#include <netinet/in.h>

/* 常量定义 */
#define XSAN_MAX_SEED_NODES 16
#define XSAN_MAX_NODES 8
#define XSAN_MAX_NAME_LEN 256
#define XSAN_MAX_PATH_LEN 4096
#define XSAN_MAX_REPLICAS 4  // 最大副本数量

typedef struct {
    uint8_t data[16];
} xsan_uuid_t;

typedef xsan_uuid_t xsan_node_id_t;
typedef xsan_uuid_t xsan_disk_id_t;
typedef xsan_uuid_t xsan_group_id_t;
typedef xsan_uuid_t xsan_volume_id_t;

/**
 * 节点地址结构
 */
typedef struct xsan_address {
    char ip[INET_ADDRSTRLEN];
    uint16_t port;
} xsan_address_t;

/**
 * 节点结构
 */
typedef struct xsan_node {
    xsan_node_id_t id;                  // 节点UUID
    char hostname[XSAN_MAX_NAME_LEN];   // 节点主机名
    xsan_address_t storage_addr;        // 存储服务地址
    xsan_address_t mgmt_addr;           // 管理服务地址
    uint32_t status;                    // 节点状态
    uint64_t total_storage;             // 总存储容量
    uint64_t available_storage;         // 可用存储容量
} xsan_node_t;

typedef void (*xsan_user_io_completion_cb_t)(void *ctx, int status);

/* Disk group types */
typedef enum {
    XSAN_DISK_GROUP_TYPE_DATA = 0,
    XSAN_DISK_GROUP_TYPE_PARITY,
    XSAN_DISK_GROUP_TYPE_CACHE,
    XSAN_DISK_GROUP_TYPE_LOG,
    XSAN_DISK_GROUP_TYPE_JBOD
} xsan_disk_group_type_t;

/* Disk group structure */
typedef struct xsan_disk_group {
    xsan_group_id_t id;
    char name[XSAN_MAX_NAME_LEN];
    xsan_disk_group_type_t type;
    uint32_t disk_count;
    uint64_t total_capacity;
    uint64_t available_capacity;
    uint32_t state;
    xsan_disk_id_t disk_ids[XSAN_MAX_REPLICAS]; // 假设最大磁盘数
} xsan_disk_group_t;

/* Volume extent mapping structure */
typedef struct xsan_volume_extent_mapping {
    xsan_volume_id_t volume_id;
    uint64_t logical_offset;
    uint64_t physical_offset;
    uint64_t length;
    xsan_disk_id_t disk_id;
    uint64_t start_block_on_disk;
    uint64_t num_blocks_on_disk;
    uint64_t volume_start_lba;
} xsan_volume_extent_mapping_t;

/* Volume allocation metadata structure */
typedef struct xsan_volume_allocation_meta {
    xsan_volume_id_t volume_id;
    xsan_group_id_t disk_group_id;
    uint32_t num_extents;
    uint64_t total_volume_blocks_logical;
    uint32_t volume_logical_block_size;
    xsan_volume_extent_mapping_t extents[XSAN_MAX_REPLICAS]; // 假设最大扩展数
} xsan_volume_allocation_meta_t;

/* Forward declarations */
struct xsan_replica_location;
typedef struct xsan_replica_location xsan_replica_location_t;

struct xsan_per_replica_op_ctx;
typedef struct xsan_per_replica_op_ctx xsan_per_replica_op_ctx_t;

struct xsan_replica_response_cb_ctx;
typedef struct xsan_replica_response_cb_ctx xsan_replica_response_cb_ctx_t;

struct xsan_connection_ctx;
typedef struct xsan_connection_ctx xsan_connection_ctx_t;

/* Constants */
#define XSAN_MAX_EXTENTS_PER_VOLUME 16

/* Message structure for inter-process communication - defined in xsan_protocol.h */

/* Node state enum */
typedef enum xsan_node_state {
    XSAN_NODE_STATE_UNKNOWN = 0,
    XSAN_NODE_STATE_ONLINE,
    XSAN_NODE_STATE_OFFLINE,
    XSAN_NODE_STATE_DEGRADED,
    XSAN_NODE_STATE_FAILED
} xsan_node_state_t;

#endif /* XSAN_TYPES_H */
